package 张三;

import java.util.Scanner;

public class Sio9 {
	static String[][] user = new String[100][4];
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		users();
		System.out.println("  图书管理系统");
		System.out.println("1.登录" + "\t" + "2.注册");
		Scanner scan=new Scanner(System.in);

		int key = sc.nextInt();
		switch (key) {
		case 1:
			login();
			break;
		case 2:
			registr();
			break;

		default:
			break;
		}
	}

	private static boolean login() {
		boolean logFlag = false;
		while (!logFlag) {
			System.out.println("用户名");
			String userName = sc.next();
			System.out.println("密码");
			String password = sc.next();
			
			boolean result = loginCheck(userName,password);
			if (result) {
				System.out.println("登录成功");
				homepage();
				logFlag = true;
			}else {
				System.out.println("登录失败");
			}
		}
		return false;
	}

	private static boolean loginCheck(String userName, String password) {
		boolean logFlag = false;
		for (int i = 0; i < user.length; i++) {
			if (userName.equals(user[i][1]) && password.equals(user[i][2])) {
				logFlag=true;
				break;
			}
		}
		return logFlag;
	}

	private static void registr() {

		while (true) {
			System.out.println("请输入部门");
			String departName = sc.next();
			System.out.println("请输入用户名");
			String userName = sc.next();
			System.out.println("请输入密码");
			String password = sc.next();
			System.out.println("确认密码");
			String password1 = sc.next();
			for (int i = 0; i < user.length; i++) {
				if (user[i][1] == null) {
					user[i][0] = departName;
					user[i][1] = userName;
					user[i][2] = password;
				}
			}
			if (password.equals(password1)) {
				System.out.println("注册成功");
				login();
				break;
			} else {
				System.out.println("两次密码不一致，请重新登录");
			}
		}
	}
	private static void homepage() {
		System.out.println("欢迎来到图书管理系统");

	}

	private static void users() {
//		部门、用户名、密码
		user[0][0] = "技术部";
		user[0][1] = "admin";
		user[0][2] = "123";
		

		user[1][0] = "人事部";
		user[1][1] = "Sio";
		user[1][2] = "456";
		

	}

}